import java.util.Scanner;
import java.util.Random;
public class Main {
    public static void main(String[] args) {

        //猜数字游戏,猜一个1~100之间的整数数字
        //1.生成一个1~100之间的随机整数作为答案
        Random random = new Random();
        int answerNum = random.nextInt(100 ) + 1;   //范围原为[0,100),+1后得规定生成的随机整数的范围[1,100]
        //2.提示用户输入一个数字                                                   //即范围为[0,99]
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入一个1~100之间的整数:");
        while(scanner.hasNextInt()){     //也可以写成while(true)
            int guessNum = scanner.nextInt();
            if(guessNum > answerNum) {
                System.out.println("猜大了，请重新输入:");
            }else if(guessNum < answerNum) {
                    System.out.println("猜小了，请重新输入:");
                }else{
                    System.out.println("恭喜你，猜对了！");
                    break;
                }
            }

        }
    }
